// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.gameStates;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import zombie.Lua.LuaEventManager;
import zombie.Lua.LuaHookManager;
import zombie.Lua.LuaManager;
import zombie.Lua.MapObjects;
import zombie.audio.ObjectAmbientEmitters;
import zombie.characters.IsoPlayer;
import zombie.characters.SurvivorFactory;
import zombie.characters.AttachedItems.AttachedLocations;
import zombie.characters.WornItems.BodyLocations;
import zombie.characters.professions.ProfessionFactory;
import zombie.characters.skills.CustomPerks;
import zombie.characters.skills.PerkFactory;
import zombie.characters.traits.TraitFactory;
import zombie.chat.ChatElement;
import zombie.core.BoxedStaticValues;
import zombie.core.Core;
import zombie.core.Languages;
import zombie.core.Rand;
import zombie.core.SpriteRenderer;
import zombie.core.Translator;
import zombie.core.logger.ExceptionLogger;
import zombie.core.opengl.RenderSettings;
import zombie.core.opengl.RenderThread;
import zombie.core.physics.WorldSimulation;
import zombie.core.profiling.PerformanceProfileProbe;
import zombie.core.skinnedmodel.DeadBodyAtlas;
import zombie.core.skinnedmodel.ModelManager;
import zombie.core.skinnedmodel.advancedanimation.AdvancedAnimator;
import zombie.core.skinnedmodel.advancedanimation.AnimationSet;
import zombie.core.skinnedmodel.model.ModelOutlines;
import zombie.core.skinnedmodel.model.WorldItemAtlas;
import zombie.core.skinnedmodel.population.BeardStyles;
import zombie.core.skinnedmodel.population.ClothingDecals;
import zombie.core.skinnedmodel.population.HairStyles;
import zombie.core.skinnedmodel.population.OutfitManager;
import zombie.core.stash.StashSystem;
import zombie.core.textures.Texture;
import zombie.core.znet.SteamFriends;
import zombie.core.znet.SteamUtils;
import zombie.debug.DebugLog;
import zombie.debug.DebugOptions;
import zombie.debug.LineDrawer;
import zombie.erosion.ErosionGlobals;
import zombie.globalObjects.CGlobalObjects;
import zombie.globalObjects.SGlobalObjects;
import zombie.input.GameKeyboard;
import zombie.input.JoypadManager;
import zombie.input.Mouse;
import zombie.inventory.ItemSoundManager;
import zombie.iso.BentFences;
import zombie.iso.BrokenFences;
import zombie.iso.BuildingDef;
import zombie.iso.ContainerOverlays;
import zombie.iso.IsoCamera;
import zombie.iso.IsoCell;
import zombie.iso.IsoChunk;
import zombie.iso.IsoChunkMap;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMarkers;
import zombie.iso.IsoMetaCell;
import zombie.iso.IsoMetaGrid;
import zombie.iso.IsoWorld;
import zombie.iso.LightingThread;
import zombie.iso.LotHeader;
import zombie.iso.SearchMode;
import zombie.iso.TileOverlays;
import zombie.iso.WorldMarkers;
import zombie.iso.WorldStreamer;
import zombie.iso.SpriteDetails.IsoFlagType;
import zombie.iso.SpriteDetails.IsoObjectType;
import zombie.iso.areas.isoregion.IsoRegions;
import zombie.iso.objects.IsoFireManager;
import zombie.iso.objects.IsoGenerator;
import zombie.iso.objects.IsoWaveSignal;
import zombie.iso.objects.RainManager;
import zombie.iso.sprite.CorpseFlies;
import zombie.iso.sprite.IsoSprite;
import zombie.iso.sprite.SkyBox;
import zombie.iso.weather.ClimateManager;
import zombie.iso.weather.Temperature;
import zombie.iso.weather.fx.WeatherFxMask;
import zombie.meta.Meta;
import zombie.modding.ActiveMods;
import zombie.network.BodyDamageSync;
import zombie.network.ChunkChecksum;
import zombie.network.ClientServerMap;
import zombie.network.GameClient;
import zombie.network.GameServer;
import zombie.network.ItemTransactionManager;
import zombie.network.MPStatistics;
import zombie.network.PassengerMap;
import zombie.network.ServerGUI;
import zombie.network.ServerOptions;
import zombie.popman.ZombiePopulationManager;
import zombie.radio.ZomboidRadio;
import zombie.sandbox.CustomSandboxOptions;
import zombie.savefile.ClientPlayerDB;
import zombie.savefile.PlayerDB;
import zombie.scripting.ScriptManager;
import zombie.spnetwork.SinglePlayerClient;
import zombie.spnetwork.SinglePlayerServer;
import zombie.text.templating.TemplateText;
import zombie.ui.ActionProgressBar;
import zombie.ui.FPSGraph;
import zombie.ui.TextDrawObject;
import zombie.ui.TextManager;
import zombie.ui.TutorialManager;
import zombie.ui.UIElement;
import zombie.ui.UIManager;
import zombie.util.StringUtils;
import zombie.vehicles.EditVehicleState;
import zombie.vehicles.PolygonalMap2;
import zombie.vehicles.VehicleCache;
import zombie.vehicles.VehicleIDMap;
import zombie.vehicles.VehicleType;
import zombie.vehicles.VehiclesDB2;
import zombie.worldMap.WorldMap;
import zombie.worldMap.WorldMapVisited;
import zombie.worldMap.editor.WorldMapEditorState;

public final class IngameState extends GameState {
    public static int WaitMul = 20;
    public static IngameState instance;
    public static float draww;
    public static float drawh;
    public static Long GameID = 0L;
    static int last = -1;
    static float xPos;
    static float yPos;
    static float offx;
    static float offy;
    static float zoom;
    static HashMap<String, Integer> ContainerTypes = new HashMap();
    static int nSaveCycle = 1800;
    static boolean bDoChars = false;
    static boolean keySpacePreviousFrame = false;
    public long numberTicks = 0L;
    public boolean Paused = false;
    public float SaveDelay = 0.0F;
    boolean alt = false;
    int insanityScareCount = 5;
    int insanitypic = -1;
    int timesincelastinsanity = 10000000;
    GameState RedirectState = null;
    boolean bDidServerDisconnectState = false;
    boolean fpsKeyDown = false;
    private final ArrayList<Long> debugTimes = new ArrayList();
    private int tickCount = 0;
    private float SadisticMusicDirectorTime;
    public boolean showAnimationViewer = false;
    public boolean showAttachmentEditor = false;
    public boolean showChunkDebugger = false;
    public boolean showGlobalObjectDebugger = false;
    public String showVehicleEditor = null;
    public String showWorldMapEditor = null;

    public IngameState() {
        instance = this;
    }

    public static void renderDebugOverhead(IsoCell cell, int drawFloor, int tilew, int _offx, int _offy) {
        Mouse.update();
        int int0 = Mouse.getX();
        int int1 = Mouse.getY();
        int0 -= _offx;
        int1 -= _offy;
        int0 /= tilew;
        int1 /= tilew;
        SpriteRenderer.instance.renderi(null, _offx, _offy, tilew * cell.getWidthInTiles(), tilew * cell.getHeightInTiles(), 0.7F, 0.7F, 0.7F, 1.0F, null);
        IsoGridSquare isoGridSquare0 = cell.getGridSquare(int0 + cell.ChunkMap[0].getWorldXMinTiles(), int1 + cell.ChunkMap[0].getWorldYMinTiles(), 0);
        if (isoGridSquare0 != null) {
            int int2 = 48;
            int int3 = 48;
            TextManager.instance.DrawString((double)int3, (double)int2, "SQUARE FLAGS", 1.0, 1.0, 1.0, 1.0);
            int2 += 20;
            int3 += 8;

            for (int int4 = 0; int4 < IsoFlagType.MAX.index(); int4++) {
                if (isoGridSquare0.Is(IsoFlagType.fromIndex(int4))) {
                    TextManager.instance.DrawString((double)int3, (double)int2, IsoFlagType.fromIndex(int4).toString(), 0.6, 0.6, 0.8, 1.0);
                    int2 += 18;
                }
            }

            int int5 = 48;
            int2 += 16;
            TextManager.instance.DrawString((double)int5, (double)int2, "SQUARE OBJECT TYPES", 1.0, 1.0, 1.0, 1.0);
            int2 += 20;
            int5 += 8;

            for (int int6 = 0; int6 < 64; int6++) {
                if (isoGridSquare0.getHasTypes().isSet(int6)) {
                    TextManager.instance.DrawString((double)int5, (double)int2, IsoObjectType.fromIndex(int6).toString(), 0.6, 0.6, 0.8, 1.0);
                    int2 += 18;
                }
            }
        }

        for (int int7 = 0; int7 < cell.getWidthInTiles(); int7++) {
            for (int int8 = 0; int8 < cell.getHeightInTiles(); int8++) {
                IsoGridSquare isoGridSquare1 = cell.getGridSquare(
                    int7 + cell.ChunkMap[0].getWorldXMinTiles(), int8 + cell.ChunkMap[0].getWorldYMinTiles(), drawFloor
                );
                if (isoGridSquare1 != null) {
                    if (isoGridSquare1.getProperties().Is(IsoFlagType.solid) || isoGridSquare1.getProperties().Is(IsoFlagType.solidtrans)) {
                        SpriteRenderer.instance.renderi(null, _offx + int7 * tilew, _offy + int8 * tilew, tilew, tilew, 0.5F, 0.5F, 0.5F, 255.0F, null);
                    } else if (!isoGridSquare1.getProperties().Is(IsoFlagType.exterior)) {
                        SpriteRenderer.instance.renderi(null, _offx + int7 * tilew, _offy + int8 * tilew, tilew, tilew, 0.8F, 0.8F, 0.8F, 1.0F, null);
                    }

                    if (isoGridSquare1.Has(IsoObjectType.tree)) {
                        SpriteRenderer.instance.renderi(null, _offx + int7 * tilew, _offy + int8 * tilew, tilew, tilew, 0.4F, 0.8F, 0.4F, 1.0F, null);
                    }

                    if (isoGridSquare1.getProperties().Is(IsoFlagType.collideN)) {
                        SpriteRenderer.instance.renderi(null, _offx + int7 * tilew, _offy + int8 * tilew, tilew, 1, 0.2F, 0.2F, 0.2F, 1.0F, null);
                    }

                    if (isoGridSquare1.getProperties().Is(IsoFlagType.collideW)) {
                        SpriteRenderer.instance.renderi(null, _offx + int7 * tilew, _offy + int8 * tilew, 1, tilew, 0.2F, 0.2F, 0.2F, 1.0F, null);
                    }
                }
            }
        }
    }

    public static float translatePointX(float x, float camX, float _zoom, float _offx) {
        x -= camX;
        x *= _zoom;
        x += _offx;
        return x + draww / 2.0F;
    }

    public static float invTranslatePointX(float x, float camX, float _zoom, float _offx) {
        x -= draww / 2.0F;
        x -= _offx;
        x /= _zoom;
        return x + camX;
    }

    public static float invTranslatePointY(float y, float camY, float _zoom, float _offy) {
        y -= drawh / 2.0F;
        y -= _offy;
        y /= _zoom;
        return y + camY;
    }

    public static float translatePointY(float y, float camY, float _zoom, float _offy) {
        y -= camY;
        y *= _zoom;
        y += _offy;
        return y + drawh / 2.0F;
    }

    public static void renderRect(float x, float y, float w, float h, float r, float g, float b, float a) {
        float float0 = translatePointX(x, xPos, zoom, offx);
        float float1 = translatePointY(y, yPos, zoom, offy);
        float float2 = translatePointX(x + w, xPos, zoom, offx);
        float float3 = translatePointY(y + h, yPos, zoom, offy);
        w = float2 - float0;
        h = float3 - float1;
        if (!(float0 >= (float)Core.getInstance().getScreenWidth())
            && !(float2 < 0.0F)
            && !(float1 >= (float)Core.getInstance().getScreenHeight())
            && !(float3 < 0.0F)) {
            SpriteRenderer.instance.render(null, float0, float1, w, h, r, g, b, a, null);
        }
    }

    public static void renderLine(float x1, float y1, float x2, float y2, float r, float g, float b, float a) {
        float float0 = translatePointX(x1, xPos, zoom, offx);
        float float1 = translatePointY(y1, yPos, zoom, offy);
        float float2 = translatePointX(x2, xPos, zoom, offx);
        float float3 = translatePointY(y2, yPos, zoom, offy);
        if ((!(float0 >= (float)Core.getInstance().getScreenWidth()) || !(float2 >= (float)Core.getInstance().getScreenWidth()))
            && (!(float1 >= (float)Core.getInstance().getScreenHeight()) || !(float3 >= (float)Core.getInstance().getScreenHeight()))
            && (!(float0 < 0.0F) || !(float2 < 0.0F))
            && (!(float1 < 0.0F) || !(float3 < 0.0F))) {
            SpriteRenderer.instance.renderline(null, (int)float0, (int)float1, (int)float2, (int)float3, r, g, b, a);
        }
    }

    public static void renderDebugOverhead2(IsoCell cell, int drawFloor, float _zoom, int _offx, int _offy, float _xPos, float _yPos, int _draww, int _drawh) {
        draww = (float)_draww;
        drawh = (float)_drawh;
        xPos = _xPos;
        yPos = _yPos;
        offx = (float)_offx;
        offy = (float)_offy;
        zoom = _zoom;
        float float0 = (float)cell.ChunkMap[0].getWorldXMinTiles();
        float float1 = (float)cell.ChunkMap[0].getWorldYMinTiles();
        float float2 = (float)cell.ChunkMap[0].getWorldXMaxTiles();
        float float3 = (float)cell.ChunkMap[0].getWorldYMaxTiles();
        renderRect(float0, float1, (float)cell.getWidthInTiles(), (float)cell.getWidthInTiles(), 0.7F, 0.7F, 0.7F, 1.0F);

        for (int int0 = 0; int0 < cell.getWidthInTiles(); int0++) {
            for (int int1 = 0; int1 < cell.getHeightInTiles(); int1++) {
                IsoGridSquare isoGridSquare = cell.getGridSquare(
                    int0 + cell.ChunkMap[0].getWorldXMinTiles(), int1 + cell.ChunkMap[0].getWorldYMinTiles(), drawFloor
                );
                float float4 = (float)int0 + float0;
                float float5 = (float)int1 + float1;
                if (isoGridSquare != null) {
                    if (isoGridSquare.getProperties().Is(IsoFlagType.solid) || isoGridSquare.getProperties().Is(IsoFlagType.solidtrans)) {
                        renderRect(float4, float5, 1.0F, 1.0F, 0.5F, 0.5F, 0.5F, 1.0F);
                    } else if (!isoGridSquare.getProperties().Is(IsoFlagType.exterior)) {
                        renderRect(float4, float5, 1.0F, 1.0F, 0.8F, 0.8F, 0.8F, 1.0F);
                    }

                    if (isoGridSquare.Has(IsoObjectType.tree)) {
                        renderRect(float4, float5, 1.0F, 1.0F, 0.4F, 0.8F, 0.4F, 1.0F);
                    }

                    if (isoGridSquare.getProperties().Is(IsoFlagType.collideN)) {
                        renderRect(float4, float5, 1.0F, 0.2F, 0.2F, 0.2F, 0.2F, 1.0F);
                    }

                    if (isoGridSquare.getProperties().Is(IsoFlagType.collideW)) {
                        renderRect(float4, float5, 0.2F, 1.0F, 0.2F, 0.2F, 0.2F, 1.0F);
                    }
                }
            }
        }

        IsoMetaGrid isoMetaGrid = IsoWorld.instance.MetaGrid;
        renderRect(
            (float)(isoMetaGrid.minX * 300),
            (float)(isoMetaGrid.minY * 300),
            (float)(isoMetaGrid.getWidth() * 300),
            (float)(isoMetaGrid.getHeight() * 300),
            1.0F,
            1.0F,
            1.0F,
            0.05F
        );
        if ((double)_zoom > 0.1) {
            for (int int2 = isoMetaGrid.minY; int2 <= isoMetaGrid.maxY; int2++) {
                renderLine(
                    (float)(isoMetaGrid.minX * 300), (float)(int2 * 300), (float)((isoMetaGrid.maxX + 1) * 300), (float)(int2 * 300), 1.0F, 1.0F, 1.0F, 0.15F
                );
            }

            for (int int3 = isoMetaGrid.minX; int3 <= isoMetaGrid.maxX; int3++) {
                renderLine(
                    (float)(int3 * 300), (float)(isoMetaGrid.minY * 300), (float)(int3 * 300), (float)((isoMetaGrid.maxY + 1) * 300), 1.0F, 1.0F, 1.0F, 0.15F
                );
            }
        }

        IsoMetaCell[][] isoMetaCell = IsoWorld.instance.MetaGrid.Grid;

        for (int int4 = 0; int4 < isoMetaCell.length; int4++) {
            for (int int5 = 0; int5 < isoMetaCell[0].length; int5++) {
                LotHeader lotHeader = isoMetaCell[int4][int5].info;
                if (lotHeader == null) {
                    renderRect(
                        (float)((isoMetaGrid.minX + int4) * 300 + 1), (float)((isoMetaGrid.minY + int5) * 300 + 1), 298.0F, 298.0F, 0.2F, 0.0F, 0.0F, 0.3F
                    );
                } else {
                    for (int int6 = 0; int6 < lotHeader.Buildings.size(); int6++) {
                        BuildingDef buildingDef = (BuildingDef)lotHeader.Buildings.get(int6);
                        if (buildingDef.bAlarmed) {
                            renderRect(
                                (float)buildingDef.getX(),
                                (float)buildingDef.getY(),
                                (float)buildingDef.getW(),
                                (float)buildingDef.getH(),
                                0.8F,
                                0.8F,
                                0.5F,
                                0.3F
                            );
                        } else {
                            renderRect(
                                (float)buildingDef.getX(),
                                (float)buildingDef.getY(),
                                (float)buildingDef.getW(),
                                (float)buildingDef.getH(),
                                0.5F,
                                0.5F,
                                0.8F,
                                0.3F
                            );
                        }
                    }
                }
            }
        }
    }

    public static void copyWorld(String src, String dest) {
        String string0 = zombie.ZomboidFileSystem.instance.getGameModeCacheDir() + File.separator + src + File.separator;
        string0 = string0.replace("/", File.separator);
        string0 = string0.replace("\\", File.separator);
        String string1 = string0.substring(0, string0.lastIndexOf(File.separator));
        string1 = string1.replace("\\", "/");
        File file0 = new File(string1);
        string0 = zombie.ZomboidFileSystem.instance.getGameModeCacheDir() + File.separator + dest + File.separator;
        string0 = string0.replace("/", File.separator);
        string0 = string0.replace("\\", File.separator);
        String string2 = string0.substring(0, string0.lastIndexOf(File.separator));
        string2 = string2.replace("\\", "/");
        File file1 = new File(string2);

        try {
            copyDirectory(file0, file1);
        } catch (IOException iOException) {
            iOException.printStackTrace();
        }
    }

    public static void copyDirectory(File sourceLocation, File targetLocation) throws IOException {
        if (sourceLocation.isDirectory()) {
            if (!targetLocation.exists()) {
                targetLocation.mkdir();
            }

            String[] string = sourceLocation.list();
            boolean _boolean = GameLoadingState.convertingFileMax == -1;
            if (_boolean) {
                GameLoadingState.convertingFileMax = string.length;
            }

            for (int _int = 0; _int < string.length; _int++) {
                if (_boolean) {
                    GameLoadingState.convertingFileCount++;
                }

                copyDirectory(new File(sourceLocation, string[_int]), new File(targetLocation, string[_int]));
            }
        } else {
            FileInputStream fileInputStream = new FileInputStream(sourceLocation);
            FileOutputStream fileOutputStream = new FileOutputStream(targetLocation);
            fileOutputStream.getChannel().transferFrom(fileInputStream.getChannel(), 0L, sourceLocation.length());
            fileInputStream.close();
            fileOutputStream.close();
        }
    }

    public static void createWorld(String worldName) {
        worldName = worldName.replace(" ", "_").trim();
        String string0 = zombie.ZomboidFileSystem.instance.getGameModeCacheDir() + File.separator + worldName + File.separator;
        string0 = string0.replace("/", File.separator);
        string0 = string0.replace("\\", File.separator);
        String string1 = string0.substring(0, string0.lastIndexOf(File.separator));
        string1 = string1.replace("\\", "/");
        File file = new File(string1);
        if (!file.exists()) {
            file.mkdirs();
        }

        Core.GameSaveWorld = worldName;
    }

    public void debugFullyStreamedIn(int squareX, int squareY) {
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(squareX, squareY, 0);
        if (isoGridSquare != null) {
            if (isoGridSquare.getBuilding() != null) {
                BuildingDef buildingDef = isoGridSquare.getBuilding().getDef();
                if (buildingDef != null) {
                    boolean _boolean = buildingDef.isFullyStreamedIn();

                    for (byte _byte = 0; _byte < buildingDef.overlappedChunks.size(); _byte += 2) {
                        short short0 = buildingDef.overlappedChunks.get(_byte);
                        short short1 = buildingDef.overlappedChunks.get(_byte + 1);
                        if (_boolean) {
                            renderRect((float)(short0 * 10), (float)(short1 * 10), 10.0F, 10.0F, 0.0F, 1.0F, 0.0F, 0.5F);
                        } else {
                            renderRect((float)(short0 * 10), (float)(short1 * 10), 10.0F, 10.0F, 1.0F, 0.0F, 0.0F, 0.5F);
                        }
                    }
                }
            }
        }
    }

    public void UpdateStuff() {
        GameClient.bIngame = true;
        this.SaveDelay = this.SaveDelay + zombie.GameTime.instance.getMultiplier();
        if (this.SaveDelay / 60.0F > 30.0F) {
            this.SaveDelay = 0.0F;
        }

        zombie.GameTime.instance.LastLastTimeOfDay = zombie.GameTime.instance.getLastTimeOfDay();
        zombie.GameTime.instance.setLastTimeOfDay(zombie.GameTime.getInstance().getTimeOfDay());
        boolean _boolean = false;
        if (!GameServer.bServer && IsoPlayer.getInstance() != null) {
            _boolean = IsoPlayer.allPlayersAsleep();
        }

        zombie.GameTime.getInstance().update(_boolean && UIManager.getFadeAlpha() == 1.0);
        if (!this.Paused) {
            ScriptManager.instance.update();
        }

        if (!this.Paused) {
            long long0 = System.nanoTime();

            try {
                zombie.WorldSoundManager.instance.update();
            } catch (Exception exception0) {
                ExceptionLogger.logException(exception0);
            }

            try {
                IsoFireManager.Update();
            } catch (Exception exception1) {
                ExceptionLogger.logException(exception1);
            }

            try {
                RainManager.Update();
            } catch (Exception exception2) {
                ExceptionLogger.logException(exception2);
            }

            Meta.instance.update();

            try {
                zombie.VirtualZombieManager.instance.update();
                zombie.MapCollisionData.instance.updateMain();
                ZombiePopulationManager.instance.updateMain();
                PolygonalMap2.instance.updateMain();
            } catch (Exception exception3) {
                ExceptionLogger.logException(exception3);
            } catch (Error error) {
                error.printStackTrace();
            }

            try {
                zombie.LootRespawn.update();
            } catch (Exception exception4) {
                ExceptionLogger.logException(exception4);
            }

            if (GameServer.bServer) {
                try {
                    zombie.AmbientStreamManager.instance.update();
                } catch (Exception exception5) {
                    ExceptionLogger.logException(exception5);
                }
            } else {
                ObjectAmbientEmitters.getInstance().update();
            }

            if (GameClient.bClient) {
                try {
                    BodyDamageSync.instance.update();
                } catch (Exception exception6) {
                    ExceptionLogger.logException(exception6);
                }
            }

            if (!GameServer.bServer) {
                try {
                    ItemSoundManager.update();
                    zombie.FliesSound.instance.update();
                    CorpseFlies.update();
                    LuaManager.call("SadisticMusicDirectorTick", null);
                    WorldMapVisited.update();
                } catch (Exception exception7) {
                    ExceptionLogger.logException(exception7);
                }
            }

            SearchMode.getInstance().update();
            RenderSettings.getInstance().update();
            long long1 = System.nanoTime();
        }
    }

    @Override
    public void enter() {
        UIManager.useUIFBO = Core.getInstance().supportsFBO() && Core.OptionUIFBO;
        if (!Core.getInstance().getUseShaders()) {
            Core.getInstance().RenderShader = null;
        }

        zombie.GameSounds.fix3DListenerPosition(false);
        IsoPlayer.getInstance().updateUsername();
        IsoPlayer.getInstance().setSceneCulled(false);
        IsoPlayer.getInstance().getInventory().addItemsToProcessItems();
        GameID = (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        GameID = GameID + (long)Rand.Next(10000000);
        zombie.ZombieSpawnRecorder.instance.init();
        if (!GameServer.bServer) {
            IsoWorld.instance.CurrentCell.ChunkMap[0].processAllLoadGridSquare();
            IsoWorld.instance.CurrentCell.ChunkMap[0].update();
            if (!GameClient.bClient) {
                LightingThread.instance.GameLoadingUpdate();
            }
        }

        try {
            zombie.MapCollisionData.instance.startGame();
        } catch (Throwable throwable) {
            ExceptionLogger.logException(throwable);
        }

        IsoWorld.instance.CurrentCell.putInVehicle(IsoPlayer.getInstance());
        zombie.SoundManager.instance.setMusicState("Tutorial".equals(Core.GameMode) ? "Tutorial" : "InGame");
        ClimateManager.getInstance().update();
        LuaEventManager.triggerEvent("OnGameStart");
        LuaEventManager.triggerEvent("OnLoad");
        if (GameClient.bClient) {
            GameClient.instance.sendPlayerConnect(IsoPlayer.getInstance());
            DebugLog.log("Waiting for player-connect response from server");

            for (; IsoPlayer.getInstance().OnlineID == -1; GameClient.instance.update()) {
                try {
                    Thread.sleep(10L);
                } catch (InterruptedException interruptedException) {
                    interruptedException.printStackTrace();
                }
            }

            ClimateManager.getInstance().update();
            LightingThread.instance.GameLoadingUpdate();
        }

        if (GameClient.bClient && SteamUtils.isSteamModeEnabled()) {
            SteamFriends.UpdateRichPresenceConnectionInfo("In game", "+connect " + GameClient.ip + ":" + GameClient.port);
        }
    }

    @Override
    public void exit() {
        DebugLog.log("EXITDEBUG: IngameState.exit 1");
        if (SteamUtils.isSteamModeEnabled()) {
            SteamFriends.UpdateRichPresenceConnectionInfo("", "");
        }

        UIManager.useUIFBO = false;
        if (FPSGraph.instance != null) {
            FPSGraph.instance.setVisible(false);
        }

        UIManager.updateBeforeFadeOut();
        zombie.SoundManager.instance.setMusicState("MainMenu");
        long _long = System.currentTimeMillis();
        boolean boolean0 = UIManager.useUIFBO;
        UIManager.useUIFBO = false;
        DebugLog.log("EXITDEBUG: IngameState.exit 2");

        while (true) {
            float _float = Math.min(1.0F, (float)(System.currentTimeMillis() - _long) / 500.0F);
            boolean boolean1 = true;

            for (int int0 = 0; int0 < IsoPlayer.numPlayers; int0++) {
                if (IsoPlayer.players[int0] != null) {
                    IsoPlayer.setInstance(IsoPlayer.players[int0]);
                    IsoCamera.CamCharacter = IsoPlayer.players[int0];
                    IsoSprite.globalOffsetX = -1.0F;
                    Core.getInstance().StartFrame(int0, boolean1);
                    IsoCamera.frameState.set(int0);
                    IsoWorld.instance.render();
                    Core.getInstance().EndFrame(int0);
                    boolean1 = false;
                }
            }

            Core.getInstance().RenderOffScreenBuffer();
            Core.getInstance().StartFrameUI();
            UIManager.render();
            UIManager.DrawTexture(
                UIManager.getBlack(), 0.0, 0.0, (double)Core.getInstance().getScreenWidth(), (double)Core.getInstance().getScreenHeight(), (double)_float
            );
            Core.getInstance().EndFrameUI();
            DebugLog.log("EXITDEBUG: IngameState.exit 3 (alpha=" + _float + ")");
            if (_float >= 1.0F) {
                UIManager.useUIFBO = boolean0;
                DebugLog.log("EXITDEBUG: IngameState.exit 4");
                RenderThread.setWaitForRenderState(false);
                SpriteRenderer.instance.notifyRenderStateQueue();

                while (WorldStreamer.instance.isBusy()) {
                    try {
                        Thread.sleep(1L);
                    } catch (InterruptedException interruptedException) {
                        interruptedException.printStackTrace();
                    }
                }

                DebugLog.log("EXITDEBUG: IngameState.exit 5");
                WorldStreamer.instance.stop();
                LightingThread.instance.stop();
                zombie.MapCollisionData.instance.stop();
                ZombiePopulationManager.instance.stop();
                PolygonalMap2.instance.stop();
                DebugLog.log("EXITDEBUG: IngameState.exit 6");

                for (int int1 = 0; int1 < IsoWorld.instance.CurrentCell.ChunkMap.length; int1++) {
                    IsoChunkMap isoChunkMap = IsoWorld.instance.CurrentCell.ChunkMap[int1];

                    for (int int2 = 0; int2 < IsoChunkMap.ChunkGridWidth * IsoChunkMap.ChunkGridWidth; int2++) {
                        IsoChunk isoChunk = isoChunkMap.getChunk(int2 % IsoChunkMap.ChunkGridWidth, int2 / IsoChunkMap.ChunkGridWidth);
                        if (isoChunk != null && isoChunk.refs.contains(isoChunkMap)) {
                            isoChunk.refs.remove(isoChunkMap);
                            if (isoChunk.refs.isEmpty()) {
                                isoChunk.removeFromWorld();
                                isoChunk.doReuseGridsquares();
                            }
                        }
                    }
                }

                ModelManager.instance.Reset();

                for (int int3 = 0; int3 < 4; int3++) {
                    IsoPlayer.players[int3] = null;
                }

                IsoPlayer.Reset();
                zombie.ZombieSpawnRecorder.instance.quit();
                DebugLog.log("EXITDEBUG: IngameState.exit 7");
                IsoPlayer.numPlayers = 1;
                Core.getInstance().OffscreenBuffer.destroy();
                WeatherFxMask.destroy();
                IsoRegions.reset();
                Temperature.reset();
                WorldMarkers.instance.reset();
                IsoMarkers.instance.reset();
                SearchMode.reset();
                ZomboidRadio.getInstance().Reset();
                IsoWaveSignal.Reset();
                ErosionGlobals.Reset();
                IsoGenerator.Reset();
                StashSystem.Reset();
                zombie.LootRespawn.Reset();
                VehicleCache.Reset();
                VehicleIDMap.instance.Reset();
                IsoWorld.instance.KillCell();
                ItemSoundManager.Reset();
                IsoChunk.Reset();
                ChunkChecksum.Reset();
                ClientServerMap.Reset();
                SinglePlayerClient.Reset();
                SinglePlayerServer.Reset();
                PassengerMap.Reset();
                DeadBodyAtlas.instance.Reset();
                WorldItemAtlas.instance.Reset();
                CorpseFlies.Reset();
                if (PlayerDB.isAvailable()) {
                    PlayerDB.getInstance().close();
                }

                VehiclesDB2.instance.Reset();
                WorldMap.Reset();
                WorldStreamer.instance = new WorldStreamer();
                WorldSimulation.instance.destroy();
                WorldSimulation.instance = new WorldSimulation();
                DebugLog.log("EXITDEBUG: IngameState.exit 8");
                zombie.VirtualZombieManager.instance.Reset();
                zombie.VirtualZombieManager.instance = new zombie.VirtualZombieManager();
                zombie.ReanimatedPlayers.instance = new zombie.ReanimatedPlayers();
                ScriptManager.instance.Reset();
                zombie.GameSounds.Reset();
                VehicleType.Reset();
                TemplateText.Reset();
                LuaEventManager.Reset();
                MapObjects.Reset();
                CGlobalObjects.Reset();
                SGlobalObjects.Reset();
                zombie.AmbientStreamManager.instance.stop();
                zombie.SoundManager.instance.stop();
                IsoPlayer.setInstance(null);
                IsoCamera.CamCharacter = null;
                TutorialManager.instance.StealControl = false;
                UIManager.init();
                ScriptManager.instance.Reset();
                ClothingDecals.Reset();
                BeardStyles.Reset();
                HairStyles.Reset();
                OutfitManager.Reset();
                AnimationSet.Reset();
                zombie.GameSounds.Reset();
                SurvivorFactory.Reset();
                ProfessionFactory.Reset();
                TraitFactory.Reset();
                ChooseGameInfo.Reset();
                AttachedLocations.Reset();
                BodyLocations.Reset();
                ContainerOverlays.instance.Reset();
                BentFences.getInstance().Reset();
                BrokenFences.getInstance().Reset();
                TileOverlays.instance.Reset();
                LuaHookManager.Reset();
                CustomPerks.Reset();
                PerkFactory.Reset();
                CustomSandboxOptions.Reset();
                zombie.SandboxOptions.Reset();
                LuaManager.init();
                JoypadManager.instance.Reset();
                GameKeyboard.doLuaKeyPressed = true;
                zombie.GameWindow.ActivatedJoyPad = null;
                zombie.GameWindow.OkToSaveOnExit = false;
                zombie.GameWindow.bLoadedAsClient = false;
                Core.bLastStand = false;
                Core.ChallengeID = null;
                Core.bTutorial = false;
                Core.getInstance().setChallenge(false);
                Core.getInstance().setForceSnow(false);
                Core.getInstance().setZombieGroupSound(true);
                Core.getInstance().setFlashIsoCursor(false);
                zombie.SystemDisabler.Reset();
                Texture.nullTextures.clear();
                DebugLog.log("EXITDEBUG: IngameState.exit 9");
                zombie.ZomboidFileSystem.instance.Reset();
                if (!Core.SoundDisabled && !GameServer.bServer) {
                    fmod.javafmod.FMOD_System_Update();
                }

                try {
                    zombie.ZomboidFileSystem.instance.init();
                } catch (IOException iOException) {
                    ExceptionLogger.logException(iOException);
                }

                Core.OptionModsEnabled = true;
                DebugLog.log("EXITDEBUG: IngameState.exit 10");
                zombie.ZomboidFileSystem.instance.loadMods("default");
                zombie.ZomboidFileSystem.instance.loadModPackFiles();
                Languages.instance.init();
                Translator.loadFiles();
                DebugLog.log("EXITDEBUG: IngameState.exit 11");
                CustomPerks.instance.init();
                CustomPerks.instance.initLua();
                CustomSandboxOptions.instance.init();
                CustomSandboxOptions.instance.initInstance(zombie.SandboxOptions.instance);
                ScriptManager.instance.Load();
                ModelManager.instance.initAnimationMeshes(true);
                ModelManager.instance.loadModAnimations();
                ClothingDecals.init();
                BeardStyles.init();
                HairStyles.init();
                OutfitManager.init();
                DebugLog.log("EXITDEBUG: IngameState.exit 12");

                try {
                    TextManager.instance.Init();
                    LuaManager.LoadDirBase();
                } catch (Exception exception0) {
                    ExceptionLogger.logException(exception0);
                }

                zombie.ZomboidGlobals.Load();
                DebugLog.log("EXITDEBUG: IngameState.exit 13");
                LuaEventManager.triggerEvent("OnGameBoot");
                zombie.SoundManager.instance.resumeSoundAndMusic();

                for (IsoPlayer isoPlayer : IsoPlayer.players) {
                    if (isoPlayer != null) {
                        isoPlayer.dirtyRecalcGridStack = true;
                    }
                }

                RenderThread.setWaitForRenderState(true);
                DebugLog.log("EXITDEBUG: IngameState.exit 14");
                return;
            }

            try {
                Thread.sleep(33L);
            } catch (Exception exception1) {
            }
        }
    }

    @Override
    public void yield() {
        zombie.SoundManager.instance.setMusicState("PauseMenu");
    }

    @Override
    public GameState redirectState() {
        if (this.RedirectState != null) {
            GameState gameState = this.RedirectState;
            this.RedirectState = null;
            return gameState;
        } else {
            return new MainScreenState();
        }
    }

    @Override
    public void reenter() {
        zombie.SoundManager.instance.setMusicState("InGame");
    }

    public void renderframetext(int nPlayer) {
        IngameState.s_performance.renderFrameText.invokeAndMeasure(this, Integer.valueOf(nPlayer), IngameState::renderFrameTextInternal);
    }

    private void renderFrameTextInternal(int int1) {
        zombie.IndieGL.disableAlphaTest();
        zombie.IndieGL.glDisable(2929);
        ArrayList arrayList = UIManager.getUI();

        for (int int0 = 0; int0 < arrayList.size(); int0++) {
            UIElement uIElement = (UIElement)arrayList.get(int0);
            if (!(uIElement instanceof ActionProgressBar)
                && uIElement.isVisible()
                && uIElement.isFollowGameWorld()
                && (uIElement.getRenderThisPlayerOnly() == -1 || uIElement.getRenderThisPlayerOnly() == int1)) {
                uIElement.render();
            }
        }

        ActionProgressBar actionProgressBar = UIManager.getProgressBar((double)int1);
        if (actionProgressBar != null && actionProgressBar.isVisible()) {
            actionProgressBar.render();
        }

        WorldMarkers.instance.render();
        IsoMarkers.instance.render();
        TextDrawObject.RenderBatch((int)int1);
        ChatElement.RenderBatch((int)int1);

        try {
            Core.getInstance().EndFrameText((int)int1);
        } catch (Exception exception) {
        }
    }

    public void renderframe(int nPlayer) {
        IngameState.s_performance.renderFrame.invokeAndMeasure(this, Integer.valueOf(nPlayer), IngameState::renderFrameInternal);
    }

    private void renderFrameInternal(int _int) {
        if (IsoPlayer.getInstance() == null) {
            IsoPlayer.setInstance(IsoPlayer.players[0]);
            IsoCamera.CamCharacter = IsoPlayer.getInstance();
        }

        RenderSettings.getInstance().applyRenderSettings((int)_int);
        ActionProgressBar actionProgressBar = UIManager.getProgressBar((double)_int);
        if (actionProgressBar != null) {
            actionProgressBar.update((int)_int);
        }

        zombie.IndieGL.disableAlphaTest();
        zombie.IndieGL.glDisable(2929);
        if (IsoPlayer.getInstance() != null && !IsoPlayer.getInstance().isAsleep() || UIManager.getFadeAlpha((double)_int) < 1.0F) {
            ModelOutlines.instance.startFrameMain((int)_int);
            IsoWorld.instance.render();
            ModelOutlines.instance.endFrameMain((int)_int);
            RenderSettings.getInstance().legacyPostRender((int)_int);
            LuaEventManager.triggerEvent("OnPostRender");
        }

        LineDrawer.clear();
        if (Core.bDebug && GameKeyboard.isKeyPressed(Core.getInstance().getKey("ToggleAnimationText"))) {
            DebugOptions.instance.Animation.Debug.setValue(!DebugOptions.instance.Animation.Debug.getValue());
        }

        try {
            Core.getInstance().EndFrame((int)_int);
        } catch (Exception exception) {
        }
    }

    public void renderframeui() {
        IngameState.s_performance.renderFrameUI.invokeAndMeasure(this, IngameState::renderFrameUI);
    }

    private void renderFrameUI() {
        if (Core.getInstance().StartFrameUI()) {
            TextManager.instance.DrawTextFromGameWorld();
            SkyBox.getInstance().draw();
            UIManager.render();
            ZomboidRadio.getInstance().render();
            if (Core.bDebug && IsoPlayer.getInstance() != null && IsoPlayer.getInstance().isGhostMode()) {
                IsoWorld.instance.CurrentCell.ChunkMap[0].drawDebugChunkMap();
            }

            DeadBodyAtlas.instance.renderUI();
            WorldItemAtlas.instance.renderUI();
            if (Core.bDebug) {
                if (GameKeyboard.isKeyDown(Core.getInstance().getKey("Display FPS"))) {
                    if (!this.fpsKeyDown) {
                        this.fpsKeyDown = true;
                        if (FPSGraph.instance == null) {
                            FPSGraph.instance = new FPSGraph();
                        }

                        FPSGraph.instance.setVisible(!FPSGraph.instance.isVisible());
                    }
                } else {
                    this.fpsKeyDown = false;
                }

                if (FPSGraph.instance != null) {
                    FPSGraph.instance.render();
                }
            }

            if (!GameServer.bServer) {
                for (int int0 = 0; int0 < IsoPlayer.numPlayers; int0++) {
                    IsoPlayer isoPlayer = IsoPlayer.players[int0];
                    if (isoPlayer != null && !isoPlayer.isDead() && isoPlayer.isAsleep()) {
                        float float0 = GameClient.bFastForward ? zombie.GameTime.getInstance().ServerTimeOfDay : zombie.GameTime.getInstance().getTimeOfDay();
                        float float1 = (float0 - (float)((int)float0)) * 60.0F;
                        String string = "media/ui/SleepClock" + (int)float1 / 10 + ".png";
                        Texture texture = Texture.getSharedTexture(string);
                        if (texture == null) {
                            break;
                        }

                        int int1 = IsoCamera.getScreenLeft(int0);
                        int int2 = IsoCamera.getScreenTop(int0);
                        int int3 = IsoCamera.getScreenWidth(int0);
                        int int4 = IsoCamera.getScreenHeight(int0);
                        SpriteRenderer.instance
                            .renderi(
                                texture,
                                int1 + int3 / 2 - texture.getWidth() / 2,
                                int2 + int4 / 2 - texture.getHeight() / 2,
                                texture.getWidth(),
                                texture.getHeight(),
                                1.0F,
                                1.0F,
                                1.0F,
                                1.0F,
                                null
                            );
                    }
                }
            }

            ActiveMods.renderUI();
            JoypadManager.instance.renderUI();
        }

        if (Core.bDebug && DebugOptions.instance.Animation.AnimRenderPicker.getValue() && IsoPlayer.players[0] != null) {
            IsoPlayer.players[0].advancedAnimator.render();
        }

        if (Core.bDebug) {
            ModelOutlines.instance.renderDebug();
        }

        Core.getInstance().EndFrameUI();
    }

    @Override
    public void render() {
        IngameState.s_performance.render.invokeAndMeasure(this, IngameState::renderInternal);
    }

    private void renderInternal() {
        boolean _boolean = true;

        for (int int0 = 0; int0 < IsoPlayer.numPlayers; int0++) {
            if (IsoPlayer.players[int0] == null) {
                if (int0 == 0) {
                    SpriteRenderer.instance.prePopulating();
                }
            } else {
                IsoPlayer.setInstance(IsoPlayer.players[int0]);
                IsoCamera.CamCharacter = IsoPlayer.players[int0];
                Core.getInstance().StartFrame(int0, _boolean);
                IsoCamera.frameState.set(int0);
                _boolean = false;
                IsoSprite.globalOffsetX = -1.0F;
                this.renderframe(int0);
            }
        }

        if (DebugOptions.instance.OffscreenBuffer.Render.getValue()) {
            Core.getInstance().RenderOffScreenBuffer();
        }

        for (int int1 = 0; int1 < IsoPlayer.numPlayers; int1++) {
            if (IsoPlayer.players[int1] != null) {
                IsoPlayer.setInstance(IsoPlayer.players[int1]);
                IsoCamera.CamCharacter = IsoPlayer.players[int1];
                IsoCamera.frameState.set(int1);
                Core.getInstance().StartFrameText(int1);
                this.renderframetext(int1);
            }
        }

        UIManager.resize();
        this.renderframeui();
    }

    @Override
    public GameStateMachine.StateAction update() {
        GameStateMachine.StateAction stateAction;
        try {
            IngameState.s_performance.update.start();
            stateAction = this.updateInternal();
        } finally {
            IngameState.s_performance.update.end();
        }

        return stateAction;
    }

    private GameStateMachine.StateAction updateInternal() {
        this.tickCount++;
        if (this.tickCount < 60) {
            for (int int0 = 0; int0 < IsoPlayer.numPlayers; int0++) {
                if (IsoPlayer.players[int0] != null) {
                    IsoPlayer.players[int0].dirtyRecalcGridStackTime = 20.0F;
                }
            }
        }

        LuaEventManager.triggerEvent("OnTickEvenPaused", BoxedStaticValues.toDouble((double)this.numberTicks));
        zombie.DebugFileWatcher.instance.update();
        AdvancedAnimator.checkModifiedFiles();
        if (Core.bDebug) {
            this.debugTimes.clear();
            this.debugTimes.add(System.nanoTime());
        }

        if (Core.bExiting) {
            DebugLog.log("EXITDEBUG: IngameState.updateInternal 1");
            Core.bExiting = false;
            if (GameClient.bClient) {
                for (int int1 = 0; int1 < IsoPlayer.numPlayers; int1++) {
                    IsoPlayer isoPlayer0 = IsoPlayer.players[int1];
                    if (isoPlayer0 != null) {
                        ClientPlayerDB.getInstance().clientSendNetworkPlayerInt(isoPlayer0);
                    }
                }

                try {
                    Thread.sleep(500L);
                } catch (InterruptedException interruptedException) {
                }

                WorldStreamer.instance.stop();
                GameClient.instance.doDisconnect("exiting");
            }

            DebugLog.log("EXITDEBUG: IngameState.updateInternal 2");
            if (PlayerDB.isAllow()) {
                PlayerDB.getInstance().saveLocalPlayersForce();
                PlayerDB.getInstance().m_canSavePlayers = false;
            }

            if (ClientPlayerDB.isAllow()) {
                ClientPlayerDB.getInstance().canSavePlayers = false;
            }

            try {
                zombie.GameWindow.save(true);
            } catch (Throwable throwable0) {
                ExceptionLogger.logException(throwable0);
            }

            DebugLog.log("EXITDEBUG: IngameState.updateInternal 3");

            try {
                LuaEventManager.triggerEvent("OnPostSave");
            } catch (Exception exception0) {
                ExceptionLogger.logException(exception0);
            }

            if (ClientPlayerDB.isAllow()) {
                ClientPlayerDB.getInstance().close();
            }

            return GameStateMachine.StateAction.Continue;
        } else if (zombie.GameWindow.bServerDisconnected) {
            TutorialManager.instance.StealControl = true;
            if (!this.bDidServerDisconnectState) {
                this.bDidServerDisconnectState = true;
                this.RedirectState = new ServerDisconnectState();
                return GameStateMachine.StateAction.Yield;
            } else {
                GameClient.connection = null;
                GameClient.instance.bConnected = false;
                GameClient.bClient = false;
                zombie.GameWindow.bServerDisconnected = false;
                return GameStateMachine.StateAction.Continue;
            }
        } else {
            if (Core.bDebug) {
                if (this.showGlobalObjectDebugger || GameKeyboard.isKeyPressed(60) && GameKeyboard.isKeyDown(29)) {
                    this.showGlobalObjectDebugger = false;
                    DebugLog.General.debugln("Activating DebugGlobalObjectState.");
                    this.RedirectState = new DebugGlobalObjectState();
                    return GameStateMachine.StateAction.Yield;
                }

                if (this.showChunkDebugger || GameKeyboard.isKeyPressed(60)) {
                    this.showChunkDebugger = false;
                    DebugLog.General.debugln("Activating DebugChunkState.");
                    this.RedirectState = DebugChunkState.checkInstance();
                    return GameStateMachine.StateAction.Yield;
                }

                if (this.showAnimationViewer || GameKeyboard.isKeyPressed(65) && GameKeyboard.isKeyDown(29)) {
                    this.showAnimationViewer = false;
                    DebugLog.General.debugln("Activating AnimationViewerState.");
                    AnimationViewerState animationViewerState = AnimationViewerState.checkInstance();
                    this.RedirectState = animationViewerState;
                    return GameStateMachine.StateAction.Yield;
                }

                if (this.showAttachmentEditor || GameKeyboard.isKeyPressed(65) && GameKeyboard.isKeyDown(42)) {
                    this.showAttachmentEditor = false;
                    DebugLog.General.debugln("Activating AttachmentEditorState.");
                    AttachmentEditorState attachmentEditorState = AttachmentEditorState.checkInstance();
                    this.RedirectState = attachmentEditorState;
                    return GameStateMachine.StateAction.Yield;
                }

                if (this.showVehicleEditor != null || GameKeyboard.isKeyPressed(65)) {
                    DebugLog.General.debugln("Activating EditVehicleState.");
                    EditVehicleState editVehicleState = EditVehicleState.checkInstance();
                    if (!StringUtils.isNullOrWhitespace(this.showVehicleEditor)) {
                        editVehicleState.setScript(this.showVehicleEditor);
                    }

                    this.showVehicleEditor = null;
                    this.RedirectState = editVehicleState;
                    return GameStateMachine.StateAction.Yield;
                }

                if (this.showWorldMapEditor != null || GameKeyboard.isKeyPressed(66)) {
                    WorldMapEditorState worldMapEditorState = WorldMapEditorState.checkInstance();
                    this.showWorldMapEditor = null;
                    this.RedirectState = worldMapEditorState;
                    return GameStateMachine.StateAction.Yield;
                }
            }

            if (Core.bDebug) {
                this.debugTimes.add(System.nanoTime());
            }

            this.timesincelastinsanity++;
            if (Core.bDebug) {
                this.debugTimes.add(System.nanoTime());
            }

            try {
                if (!GameServer.bServer && IsoPlayer.getInstance() != null && IsoPlayer.allPlayersDead()) {
                    if (IsoPlayer.getInstance() != null) {
                        UIManager.getSpeedControls().SetCurrentGameSpeed(1);
                    }

                    IsoCamera.update();
                }

                this.alt = !this.alt;
                if (!GameServer.bServer) {
                    WaitMul = 1;
                    if (UIManager.getSpeedControls() != null) {
                        if (UIManager.getSpeedControls().getCurrentGameSpeed() == 2) {
                            WaitMul = 15;
                        }

                        if (UIManager.getSpeedControls().getCurrentGameSpeed() == 3) {
                            WaitMul = 30;
                        }
                    }
                }

                if (Core.bDebug) {
                    this.debugTimes.add(System.nanoTime());
                }

                if (GameServer.bServer) {
                    if (GameServer.Players.isEmpty() && ServerOptions.instance.PauseEmpty.getValue()) {
                        this.Paused = true;
                    } else {
                        this.Paused = false;
                    }
                }

                if (!this.Paused || GameClient.bClient) {
                    try {
                        if (IsoCamera.CamCharacter != null && IsoWorld.instance.bDoChunkMapUpdate) {
                            for (int int2 = 0; int2 < IsoPlayer.numPlayers; int2++) {
                                if (IsoPlayer.players[int2] != null && !IsoWorld.instance.CurrentCell.ChunkMap[int2].ignore) {
                                    if (!GameServer.bServer) {
                                        IsoCamera.CamCharacter = IsoPlayer.players[int2];
                                        IsoPlayer.setInstance(IsoPlayer.players[int2]);
                                    }

                                    if (!GameServer.bServer) {
                                        IsoWorld.instance.CurrentCell.ChunkMap[int2].ProcessChunkPos(IsoCamera.CamCharacter);
                                    }
                                }
                            }
                        }

                        if (Core.bDebug) {
                            this.debugTimes.add(System.nanoTime());
                        }

                        IsoWorld.instance.update();
                        if (Core.bDebug) {
                            this.debugTimes.add(System.nanoTime());
                        }

                        ZomboidRadio.getInstance().update();
                        this.UpdateStuff();
                        LuaEventManager.triggerEvent("OnTick", (double)this.numberTicks);
                        this.numberTicks = Math.max(this.numberTicks + 1L, 0L);
                    } catch (Exception exception1) {
                        ExceptionLogger.logException(exception1);
                        if (!GameServer.bServer) {
                            if (GameClient.bClient) {
                                for (int int3 = 0; int3 < IsoPlayer.numPlayers; int3++) {
                                    IsoPlayer isoPlayer1 = IsoPlayer.players[int3];
                                    if (isoPlayer1 != null) {
                                        ClientPlayerDB.getInstance().clientSendNetworkPlayerInt(isoPlayer1);
                                    }
                                }

                                WorldStreamer.instance.stop();
                            }

                            String string = Core.GameSaveWorld;
                            createWorld(Core.GameSaveWorld + "_crash");
                            copyWorld(string, Core.GameSaveWorld);
                            if (GameClient.bClient) {
                                if (PlayerDB.isAllow()) {
                                    PlayerDB.getInstance().saveLocalPlayersForce();
                                    PlayerDB.getInstance().m_canSavePlayers = false;
                                }

                                if (ClientPlayerDB.isAllow()) {
                                    ClientPlayerDB.getInstance().canSavePlayers = false;
                                }
                            }

                            try {
                                zombie.GameWindow.save(true);
                            } catch (Throwable throwable1) {
                                ExceptionLogger.logException(throwable1);
                            }

                            if (GameClient.bClient) {
                                try {
                                    LuaEventManager.triggerEvent("OnPostSave");
                                } catch (Exception exception2) {
                                    ExceptionLogger.logException(exception2);
                                }

                                if (ClientPlayerDB.isAllow()) {
                                    ClientPlayerDB.getInstance().close();
                                }
                            }
                        }

                        if (GameClient.bClient) {
                            GameClient.instance.doDisconnect("crash");
                        }

                        return GameStateMachine.StateAction.Continue;
                    }
                }
            } catch (Exception exception3) {
                System.err.println("IngameState.update caught an exception.");
                ExceptionLogger.logException(exception3);
            }

            if (Core.bDebug) {
                this.debugTimes.add(System.nanoTime());
            }

            if (!GameServer.bServer || ServerGUI.isCreated()) {
                ModelManager.instance.update();
            }

            if (Core.bDebug && FPSGraph.instance != null) {
                FPSGraph.instance.addUpdate(System.currentTimeMillis());
                FPSGraph.instance.update();
            }

            if (GameClient.bClient || GameServer.bServer) {
                ItemTransactionManager.update();
                MPStatistics.Update();
            }

            return GameStateMachine.StateAction.Remain;
        }
    }

    private static class s_performance {
        static final PerformanceProfileProbe render = new PerformanceProfileProbe("IngameState.render");
        static final PerformanceProfileProbe renderFrame = new PerformanceProfileProbe("IngameState.renderFrame");
        static final PerformanceProfileProbe renderFrameText = new PerformanceProfileProbe("IngameState.renderFrameText");
        static final PerformanceProfileProbe renderFrameUI = new PerformanceProfileProbe("IngameState.renderFrameUI");
        static final PerformanceProfileProbe update = new PerformanceProfileProbe("IngameState.update");
    }
}
